<template>
  <div class="mod-config">
    <el-form inline :model="dataForm" @keyup.enter.native="getDataList()">
      <!-- 简单搜索框 -->
      <el-form-item>
        <el-input v-model="dataForm.key" disabled placeholder="参数名" ></el-input>
      </el-form-item>

      <!-- 动态表单抽屉 -->
      <el-form-item label="">

        <draw-form :FormData="Parameters.FormData" :labels="Parameters.labels" title="乘客参数"
          :options="Parameters.options" @submit="handleDrawerSubmit"
          :FormDataType="Parameters.FormDataType"></draw-form>

      </el-form-item>

      <!-- 操作按钮 -->
      <el-form-item>
        <!-- <el-button @click="getDataList()">查询</el-button> -->
        <el-button v-if="isAuth('generator:customerinfo:save')" type="primary"
          @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('generator:customerinfo:delete')" type="danger" @click="deleteHandle()"
          :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table height="700"  :data="dataList" :border="true" v-loading="dataListLoading" @selection-change="selectionChangeHandle"
      style="width: 100%">
      <el-table-column type="selection" header-align="'center'" :align="'center'" width="50">
      </el-table-column>
      <el-table-column sortable  prop="id" header-align="'center'" :align="'center'" label="主键">
      </el-table-column>
      <el-table-column prop="wxOpenId" header-align="'center'" :align="'center'" label="微信openId">
      </el-table-column>
      <el-table-column prop="nickname" header-align="'center'" :align="'center'" label="客户昵称">
      </el-table-column>
      <el-table-column prop="gender" header-align="'center'" :align="'center'" label="性别">
      </el-table-column>
      <el-table-column prop="avatarUrl" header-align="'center'" :align="'center'" label="头像">
      </el-table-column>
      <el-table-column prop="phone" header-align="'center'" :align="'center'" label="电话">
      </el-table-column>
      <el-table-column prop="status" header-align="'center'" :align="'center'" label="状态">
      </el-table-column>
      <el-table-column sortable prop="createTime" header-align="'center'" :align="'center'" label="创建时间">
      </el-table-column>
      <el-table-column sortable prop="updateTime" header-align="'center'" :align="'center'" label="修改时间">
      </el-table-column>
      <el-table-column prop="isDeleted" header-align="'center'" :align="'center'" label="是否删除">
      </el-table-column>
      <el-table-column fixed="right" header-align="'center'" :align="'center'" width="300" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit"  size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="danger" icon="el-icon-delete"  size="small" @click="deleteHandle(scope.row.id)">删除</el-button>  <el-button type="primary"  icon="el-icon-more" size="mini" @click="showDeadline(scope.row)">显示详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 新增/修改弹窗 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./customerinfo-add-or-update";
import drawForm from "@/Views/common/drawForm.vue";
import http from "@/utils/request";

export default {
  components: {
    AddOrUpdate,
    drawForm,
  },
  data() {
    return {
      dataForm: {
        key: "",
      },
      Parameters: {
        FormDataType: [
          "string",
          "array",
          "string",
          "array",
          "dateTime",
          "dateTime",
          "boolean"
        ],
        FormData: {
          nickname: "",
          gender: "",
          phone: "",
          status: null,
          createTime: null,
          updateTime: null,
          isDelete:null
        },
        labels: {
          nickname: "客户昵称",
          gender: "性别",
          phone: "电话",
          status: "状态",
          createTime: '创建时间',
          updateTime: '修改时间',
          isDelete:'是否被删除'
        },
        options: {
          gender: [
            { value: "male", label: "男" },
            { value: "female", label: "女" },
          ],
          status: [
            { value: 1, label: "有效" },
            { value: 2, label: "禁用" },
          ],
        },
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
    };
  },
  mounted() {
      this.getDataList();
      // 在这个地方进行这个获取这个前端 的数据内容
      // alert("开始获取这个数据内容")
    },
  methods: {
    isAuth() {
      return true;
    },
    //  这个是这个前端的获取这个数据内容
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      http({
        url: "/customer/customerinfo/list",
        method: "get",
        params: {
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key,
          ...this.Parameters.FormData, // 将动态表单数据传递给后端
        },
      })
        .then(({ data }) => {
          console.log(data+"获取到的前端的数据内容")
          // 
          if (data && data.code === 200) {
            this.dataList = data.page.list;
            this.totalPage = data.page.totalCount;
          } else {
            this.dataList = [];
            this.totalPage = 0;
          }
          this.dataListLoading = false;
        })
        .catch((error) => {
          this.dataListLoading = false;
          console.log(error);
          this.$message.error("获取乘客信息失败，请重试！");
        });
    },
    // 处理抽屉提交事件
    handleDrawerSubmit(formData) {
      console.log(formData);

      this.Parameters.FormData = formData; // 更新动态表单数据
      this.getDataList(); // 重新加载数据
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      console.log(this.addOrUpdateVisible);
      
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      const ids = id
        ? [id]
        : this.dataListSelections.map((item) => item.id);
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          http({
            url: "/customer/customerinfo/delete",
            method: "post",
            data: ids,
          }).then(({ data }) => {
            if (data && data.code === 200) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => { });
    },
  },
};
</script>